﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PhotoGallery.Abstract;
using PhotoGallery.Concrete;
using PhotoGallery.Entities;

namespace PhotoGallery.Controllers
{
    public class HomeController : Controller
    {
        private ICategoryRepository CategoryRepository;
        private IFavoritsPhotoRepository FavoritsPhotoRepository;

        public HomeController()
        {
            string connString = @"server=.\SQLEXPRESS; Integrated Security=SSPI ;database=PhotoGallery;";
            CategoryRepository = new SqlCategoryRepository(connString);
            FavoritsPhotoRepository = new SqlFavoritsPhotoRepository(connString);
        }
        
        public ActionResult Gallery()
        {
          return View(CategoryRepository.Category.ToList());
        }


        public FileContentResult GetCategoryImage(int? CategoryId)
        {
            Category category = (from p in CategoryRepository.Category
                                 where p.CategoryId == CategoryId
                           select p).First();

            return File(category.CategoryImage, category.ImageMimeType);
        }

        public FileContentResult GetSmallImageFavorits(Guid UserId)
        {
            FavoritsPhoto favoritsphoto = (from p in FavoritsPhotoRepository.FavoritsPhoto
                                           where p.UserId == UserId
                                           select p).First();

            return File(favoritsphoto.Image.SmallImage, favoritsphoto.Image.ImageMimeType);
        }



        public ActionResult About()
        {
            return View();
        }

        public ActionResult Photos()
        {
            return View(FavoritsPhotoRepository.FavoritsPhoto.ToList());
        }

        public ActionResult Profile()
        {
            return View();
        }

        public ActionResult Contacts()
        {
            return View();
        }

        






    }
}
